<?php

declare(strict_types=1);
/**
 * Author: Zane
 * Email: 873934580@qq.com
 * Date: 2022/3/2.
 */

namespace App\Http\Middleware;

use App\Http\Service\LogService;

class LogMiddleware
{
    public static $route;

    public function handle($request, \Closure $next)
    {
        $response = $next($request);
        static::$route = request()->route();

        return $response;
    }

    /**
     * 日志记录.
     *
     * @param $request
     * @param $response
     */
    public function terminate($request, $response): void
    {
        LogService::log($request, $response, static::$route);
    }
}
